package com.ruoyi.web.controller.front;

import java.util.List;

import com.ruoyi.common.utils.UUIDFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.front.domain.SCopyright;
import com.ruoyi.front.service.ISCopyrightService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * copyrightController
 * 
 * @author jyp
 * @date 2021-07-28
 */
@Controller
@RequestMapping("/front/copyright")
public class SCopyrightController extends BaseController
{
    private String prefix = "front/copyright";

    @Autowired
    private ISCopyrightService sCopyrightService;

    @RequiresPermissions("front:copyright:view")
    @GetMapping()
    public String copyright()
    {
        return prefix + "/copyright";
    }

    /**
     * 查询copyright列表
     */
    @RequiresPermissions("front:copyright:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SCopyright sCopyright)
    {
        startPage();
        List<SCopyright> list = sCopyrightService.selectSCopyrightList(sCopyright);
        return getDataTable(list);
    }

    /**
     * 导出copyright列表
     */
    @RequiresPermissions("front:copyright:export")
    @Log(title = "copyright", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SCopyright sCopyright)
    {
        List<SCopyright> list = sCopyrightService.selectSCopyrightList(sCopyright);
        ExcelUtil<SCopyright> util = new ExcelUtil<SCopyright>(SCopyright.class);
        return util.exportExcel(list, "copyright");
    }

    /**
     * 新增copyright
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存copyright
     */
    @RequiresPermissions("front:copyright:add")
    @Log(title = "copyright", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SCopyright sCopyright)
    {
        sCopyright.setId(UUIDFactory.getStringId());
        return toAjax(sCopyrightService.insertSCopyright(sCopyright));
    }

    /**
     * 修改copyright
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SCopyright sCopyright = sCopyrightService.selectSCopyrightById(id);
        mmap.put("sCopyright", sCopyright);
        return prefix + "/edit";
    }

    /**
     * 修改保存copyright
     */
    @RequiresPermissions("front:copyright:edit")
    @Log(title = "copyright", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SCopyright sCopyright)
    {
        return toAjax(sCopyrightService.updateSCopyright(sCopyright));
    }

    /**
     * 删除copyright
     */
    @RequiresPermissions("front:copyright:remove")
    @Log(title = "copyright", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sCopyrightService.deleteSCopyrightByIds(ids));
    }
}
